﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BingZi.HY.Core;
using XCode;
using System.Collections;
using BingZi.WebControls;
using NewLife.Web;

namespace FrameWork.web
{
    public partial class indexLast : BaseTemplatePage
    {

        #region "==属性=="
        /// <summary>
        /// 分类编号
        /// </summary>
        public Int32 CategoryID = WebHelper.GetIntParam(HttpContext.Current.Request, "CategoryID", 0);

        /// <summary>
        /// 页码
        /// </summary>
        public Int32 PageIndex = WebHelper.GetIntParam(HttpContext.Current.Request, "PageIndex", 1);

        /// <summary>
        /// 排序字段
        /// </summary>
        public String Orderfld = WebHelper.GetStringParam(HttpContext.Current.Request, "Orderfld", "ID");


        /// <summary>
        /// 排序类型（默认倒序）
        /// </summary>
        public Int32 OrderType = WebHelper.GetIntParam(HttpContext.Current.Request, "OrderType", 1);


        #endregion




        #region "==方法=="

        /// <summary>
        /// 绑定页面元素
        /// </summary>
        private void BindPageItem()
        {
            NewLife.QueryParam qp = new NewLife.QueryParam();
            qp.Orderfld = Orderfld;
            qp.OrderType = OrderType;
            qp.PageSize = 20;
            qp.PageIndex = PageIndex;


            if (CategoryID > 0)
            {
                qp.Where.Add(new NewLife.SearchParam(app_Product._.CategoryID, app_Category.FindIDs(CategoryID), NewLife.SearchType.In));
            }
            qp.Where.Add(new NewLife.SearchParam(app_Product._.Status, (int)EnumProductStatus.Published, NewLife.SearchType.Equal));
            int RecordCount = 0;
            EntityList<app_Product> ProductList = app_Product.FindAll(qp, out RecordCount);

            Hashtable Puts = new Hashtable();
            Puts.Add("ProductList", ProductList);
            Puts.Add("Pager", new Pager(qp.PageIndex, qp.PageSize, RecordCount, true).CreateHtml());
            Puts.Add("PageIndex", PageIndex);

            Puts.Add("CategoryID", CategoryID);

            app_Category Category = app_Category.FindByKeyForEdit(CategoryID);
            if (Category != null && Category.CategoryID > 0 && Category.C_ParentID != 0)
            {
                Puts.Add("MenuID", Category.C_ParentID);
            }
            else
            {
                Puts.Add("MenuID", CategoryID);
            }

            //要测试的方法
            Response.Write(ViewTemplate(EnumTemplateFile.indexLast,Puts));
        }

        #endregion



        #region "==事件=="


        /// <summary>
        /// 页面加载
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
 
                //绑定页面元素
                BindPageItem();
  

            }

        }




        #endregion





    }
}